
Ext.onReady(function(){

Ext.QuickTips.init();

var detailEl;


var contentPanel = {
id: 'content-panel',
region: 'center', // this is what makes this panel into a region within the containing layout
layout: 'card',
margins: '2 5 5 0',
activeItem: 0,
border: false,
items: [
fases, EntregaArtefactoGrupo
]
};

var contentPanelIzq = {
  id: 'contentPanelIzq-panel',
  title: 'Material',
  region: 'east', // this is what makes this panel into a region within the containing layout
  layout: 'card',
  margins: '2 5 5 0',
  activeItem: 0,
  split:true,
  width: 400,
  closable: true,
  collapsible: true,
  border: false,
  items: [
  IniciaMaterial, materialArtefacto,ActualizarUsuario, 
  ]
};

var encabezadoPanel = {
  id: 'encabezado-panel',
  region: 'north', 
  split: true,
  height: 300,
  minSize: 150,
  autoScroll: true,
  border: false,
  items: [
	imagenLogo,
	menu
	]
};
// Go ahead and create the TreePanel now so that we can use it below
var treePanel = new Ext.tree.TreePanel({
	id: 'tree-panel',
	title: 'Perfil Estudiante',
	region:'center',
	split: true,
	/*height: 300,
	minSize: 150,*/
	width: 270,
	height: 720,
               // minSize: 100,
                maxSize: 500,
	autoScroll: true,

	// tree-specific configs:
	rootVisible: false,
	//lines: false,
	//singleExpand: true,
	//useArrows: true,

	loader: new Ext.tree.TreeLoader({
		url: '../modulo_estudiante/controlador/inicio.php',  
		baseParams: {accion:'arbolEstudiante'}
	}),
	root: new Ext.tree.AsyncTreeNode()
});
var cursoConf='';

// Assign the changeLayout function to be called on tree node click.
treePanel.on('click', function(n){
	var sn = this.selModel.selNode || {}; // selNode is null on initial selection
	if(n.leaf && n.id != sn.id){  // ignore clicks on folders and currently selected node
                  var cadena=n.id;
console.log(cadena);
                  var layout = cadena.split(" ");
                  IDActi=layout[0];
                  IDArt=layout[1];
                  console.log(layout);
				  

				  //cargarGrupos(cursoConf);
                 cargarMaterialArtefacto(IDActi,IDArt);
				  
	Ext.getCmp('contentPanelIzq-panel').layout.setActiveItem('materialArtefacto-panel');
	/*if(!detailEl){
		var bd = Ext.getCmp('details-panel').body;
		bd.update('').setStyle('background','#fff');
		detailEl = bd.createChild(); //create default empty div
	}
	//detailEl.hide().update(Ext.getDom(n.id+'-details').innerHTML).slideIn('l', {stopFx:true,duration:.2});*/
	}
});

// This is the Details panel that contains the description for each example layout.
var detailsPanel = {
	id: 'details-panel',
	title: 'Informacion',
	region: 'center',
	bodyStyle: 'padding-bottom:15px;background:#eee;',
	autachanteoScroll: true,
	html: '<p class="details-info">Cuando seleccione alg\xFAn elemento del men&uacute; aqu\xED encontrara informaci&oacute;n.</p>'
};
//fin de arbol dinamico

// Finally, build the main layout once all the pieces are ready.  This is also a good
// example of putting together a full-screen BorderLayout within a Viewport.
new Ext.Viewport({
	layout: 'border',
	//title: 'Ext Layout Browser',
	items: [
                {
                  //xtype: 'box',
                  layout: 'menu',
                  region: 'north',
                  //applyTo: 'header',
                  height: 80,
                  width: 275,
                  minSize: 100,
                  maxSize: 500,
                  items: [encabezadoPanel, 
                  ]
                },{
                layout: 'border',url: '../modulo_estudiante/controlador/inicio.php',
                id: 'layout-browser',
                region:'west',
                border: false,
                split:true,
                margins: '2 0 5 5',
                width: 200,
                minSize: 100,
                maxSize: 500,
                items: [treePanel
				//, detailsPanel
				]
                },
                contentPanel,
                contentPanelIzq
                 ],
	renderTo: Ext.getBody()
	});
});


function  cargarMaterialArtefacto(IDActi,IDArt)
{
    Ext.Ajax.request({
        url: '../modulo_estudiante/controlador/inicio.php',
        method: 'POST',
        mBind: true,
        params: { accion: 'consultarMaterial', art: IDArt },
        success: function(responseObject)
        {
            responseData = Ext.util.JSON.decode(responseObject.responseText);
            storematerial.loadData(responseData);
        },
        failure: function(f, a)
        {
          
          }
                                             
      });
}

